package com.party.refund.jms.service.impl;

import com.party.common.constant.Constant;
import com.party.refund.jms.service.ISupportRefundPubulisherService;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.MapMessage;
import javax.jms.Session;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: huangzequn
 * @Date: 2019/5/16 15:39
 */
@Service
public class SupportRefundPubulisherService implements ISupportRefundPubulisherService {

    private JmsTemplate jmsRefundTemplateWeb;

    private ExecutorService threadPool = Executors.newFixedThreadPool(100);


    public void setJmsRefundTemplateWeb(JmsTemplate jmsRefundTemplateWeb) {
        this.jmsRefundTemplateWeb = jmsRefundTemplateWeb;
    }

    public void send(final String supportId,final String isTwiceRefund) {
        threadPool.execute(() -> sendMessage(supportId,isTwiceRefund));
    }

    public void sendMessage(final String supportId,final String isTwiceRefund) {
        jmsRefundTemplateWeb.send((Session session) -> {
            MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString(Constant.TYPE_KEY, supportId);
            mapMessage.setString("isTwiceRefund",isTwiceRefund);
            return mapMessage;
        });
    }

}
